<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>修改密码</title>
    <meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" href="resources/bootstrap/css/bootstrap.min.css">
	<script src="resources/common/jquery/jquery-3.2.1.min.js"></script>
	<script src="resources/bootstrap/js/bootstrap.min.js"></script>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
	.btn{
		    float: right;
		    font-size: 14px;
		    color: #fff;
		    background: #00b4ef;
		    border-radius: 30px;
		    padding: 10px 25px;
		    border: none;
		    text-transform: capitalize;
		    transition: all 0.5s ease 0s;
		}
</style>
  </head>
  <script type="text/javascript">
  		var re = function(){
  			$("#opwd").val("");
            $("#npwd").val("");
            $("#npwd2").val("");
            $("#npwd").popover('hide');
			$("#npwd2").popover('hide');
  		}
  		$(document).ready(
  			function(){
  				$("#res").click(re);
  			}
  		);
  	var sub = function(){
  		var opwd = $("#opwd").val();
     	var pwd1 = $("#npwd").val();
		var pwd2 = $("#npwd2").val();
		if(opwd=='' && pwd1=='' && pwd2=='' ){
			alert("密码不能为空");
			return false;
		}
		var paramdata = {
		"opwd":opwd,
		"npwd":pwd1
			}
		$.ajax({
     		url:'updatepwd.do',
     		type:'post',
     		async:true,//异步执行
     		timeout:5000,//超时时间5s
     		data:JSON.stringify(paramdata),
          	contentType:'application/json;charset=utf-8',//参数类型
     		success:function(data){//成功
     			if(data.succ == 'true'){
     				alert("修改成功");
     				re();
     			}else{
     				alert(data.msg);
     			}
     		},
     		error:function(xhr,textStatus){//失败
     			alert("保存失败");
     		}
     	});
  	}
  	var keyup = function(kid){
  		var pwd1 = $("#npwd").val();
  		var pwd2 = $("#npwd2").val();
  		if(pwd1 != pwd2){
  			$("#"+kid).popover('show');
  		}
  	}
  	var keyf = function(){
		$("#npwd").popover('hide');
		$("#npwd2").popover('hide');
  	}
  </script>
  <body class="bg-warning" style="position: relative;">
    <div class="col-md-offset-4 col-sm-offset-4 container col-sm-4 col-md-4 bg-info" style="position: absolute;top: 15%">
    <form class="form-horizontal" action="" method="post">
   <div class="form-group">
    <label class="col-sm-12"></label>
  </div>
  <div class="form-group">
    <label for="opwd" class="col-sm-2 control-label">旧密码</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name="opwd" id="opwd" placeholder="旧密码" >
    </div>
  </div>
  <div class="form-group">
    <label for="npwd" class="col-sm-2 control-label">新密码</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name="npwd" id="npwd" placeholder="新密码"
      data-container="body" data-toggle="popover" data-placement="right"
			data-content="密码不一致"  onblur="keyup('npwd');" onfocus="keyf();">
    </div>
  </div>
  <div class="form-group">
    <label for="npwd2" class="col-sm-2 control-label">新密码</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name="npwd2" id="npwd2" placeholder="新密码"
      data-container="body" data-toggle="popover" data-placement="right"
			data-content="密码不一致"  onblur="keyup('npwd2');" onfocus="keyf();">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="button" id="upp" class="btn btn-primary" onclick="sub();">保存</button>
      <button type="button" id="res" class="btn btn-primary">重置</button>
    </div>
  </div>
</form>
    </div>
  </body>
</html>
